package com.example.controller.project;

import com.example.entity.ProjectResourceVO;
import com.example.service.projectResource.ProjectResourceService;
import com.example.util.R;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * --- 无事发生 ---
 *
 * @author YangYiBo
 * @date 2024/12/2
 * @desc
 */
@RestController
@RequestMapping("/pr/resource")
public class ProjectResourceController {
    @Autowired
    private ProjectResourceService projectResourceService;

    /**
     * 模糊查询
     */
    @PostMapping("/list")
    public R list(@RequestBody ProjectResourceVO projectResourceVO) {

        System.out.println(projectResourceVO);
        PageHelper.startPage(projectResourceVO.getPageNum(), projectResourceVO.getPageSize());

        List<ProjectResourceVO> list = projectResourceService.list(projectResourceVO);

        PageInfo<ProjectResourceVO> pageInfo = new PageInfo(list);

        return R.ok(pageInfo);
    }


    /**
     * 根据资源ID删除
     */
    @GetMapping("/delById")
    public R delById(int resourceId) {
        int i = projectResourceService.delById(resourceId);
        if (i > 0) {
            return R.ok();
        }
        return R.fail();
    }

    /**
     * 批量删除
     */
    @GetMapping("/delBatch")
    public R delBatch(@RequestParam ArrayList<Integer> ids) {
        int i = projectResourceService.delBatch(ids);
        if (i > 0) {
            return R.ok();
        }
        return R.fail();
    }

    /**
     * 添加项目资源
     */
    @PostMapping("/add")
    public R add(@RequestBody ProjectResourceVO projectResourceVO) {
        projectResourceService.add(projectResourceVO);
        return R.ok();
    }
}
